//
//  ZYXLoginViewController.m
//  RuiBeiKang
//
//  Created by 代码女神 on 2019/1/4.
//  Copyright © 2019年 JW. All rights reserved.
//

#import "ZYXLoginViewController.h"
#import "ZYXRegistViewController.h"
#import "ZYXFindPassViewController.h"
#import "BaseTabBarVC.h"
#import "YCDownloadSession.h"
@interface ZYXLoginViewController ()

@property (weak, nonatomic) IBOutlet UITextField *phoneTextF;
@property (weak, nonatomic) IBOutlet UITextField *passTextF;

@end

@implementation ZYXLoginViewController
+ (void)setupLogin {

    ZYXLoginViewController *vc = [ZYXLoginViewController new];
    BaseNavigationVC *nav = [[BaseNavigationVC alloc] initWithRootViewController:vc];
    [KEYWINDOW.rootViewController presentViewController:nav animated:YES completion:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
}       

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

}

- (void)setupViews{
    self.view.backgroundColor = [UIColor whiteColor];
    self.isHiddenNav = YES;
}

#pragma mark Action
- (IBAction)loginAction:(id)sender {
    
    [self.view endEditing:YES];
    
    //登录
    NSString *phone = self.phoneTextF.text;
    NSString *pass = self.passTextF.text;
    
    if (![Functions isPhoneNumber:phone]|| ![Functions validateMobile:phone]){
        [JKToast showWithText:@"手机号码格式不正确"];
        return;
    }
    
    if (![Functions isPassward:pass]){
        [JKToast showWithText:@"密码格式不正确"];
        return;
    }
    [NetWork POSTWithUrlString:kInterfaceAllUrl(PATH_userLogin) parmas:@{@"username":phone,@"password":pass} successBloock:^(NSDictionary *responseObject) {
        NSLog(@"%@",responseObject);
        if ([responseObject[@"code"] isEqualToNumber:@200]) {
            
            UserInfo *user = [UserInfo sharedUser];
            [user cleanUserInfo];
            [user setWithDic:responseObject[@"data"]];
//            BaseTabBarVC *vc = [[BaseTabBarVC alloc]init];
//            APPDelegate.window.rootViewController = vc;
//            [APPDelegate.window makeKeyAndVisible];
//            [self.navigationController popViewControllerAnimated:YES];
            [self.navigationController dismissViewControllerAnimated:YES completion:nil];
            
        }else{
            [JKToast showWithText:responseObject[@"message"]];
        }
        
        
    } failureBlock:^(NSError *error) {
        
    }];
    


   
    
}
- (IBAction)registAction:(id)sender {
    //注册账号
    ZYXRegistViewController *ctrl = [[ZYXRegistViewController alloc] init];
    [self.navigationController pushViewController:ctrl animated:YES];
}
- (IBAction)forgetPassAction:(id)sender {
    //忘记密码
    ZYXFindPassViewController *ctrl = [[ZYXFindPassViewController alloc] init];
    [self.navigationController pushViewController:ctrl animated:YES];
}
/*
///CESHI
-(void)setUpDownload {
    NSString *uid = UID
    if (uid.length >0) {
        NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true).firstObject;
        path = [path stringByAppendingPathComponent:@"download"];
        NSLog(@"%@",path);
        YCDConfig *config = [YCDConfig new];
        config.saveRootPath = path;
        config.uid = UID;
        config.maxTaskCount = 3;
        config.taskCachekMode = YCDownloadTaskCacheModeKeep;
        config.launchAutoResumeDownload = true;
        [YCDownloadManager mgrWithConfig:config];
        [YCDownloadManager allowsCellularAccess:YES];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:kDownloadTaskFinishedNoti object:nil];
    }
    
}
*/
- (IBAction)clickBack:(UIButton *)sender {
        [[NSNotificationCenter defaultCenter] postNotificationName:CancelLandingNotification object:nil];
           [self dismissViewControllerAnimated:YES completion:nil];
    
    


}
@end
